package com.trsvax.tapestry.instrumentation;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.spi.LoggingEvent;

public class ThreadDetail {
	private List<LoggingEvent> logs = new ArrayList<LoggingEvent>();
	private HttpServletRequest request;
	private Integer threadID;
	private String url;
	private String pageName;
	private Class pageClass;
	private long startTime = new Date().getTime();
	private long endTime;

	// public String toString() {
	// return pageName;
	// }

	public List<LoggingEvent> getList(Class class1) {
		if (class1 == null)
			return Collections.EMPTY_LIST;

		ArrayList<LoggingEvent> l = new ArrayList<LoggingEvent>();
		for (LoggingEvent e : logs) {
			if (e.getLoggerName().equals(class1.getName())) {
				l.add(e);
			}
		}
		return l;
	}

	public List<LoggingEvent> getList(String name) {
		ArrayList<LoggingEvent> l = new ArrayList<LoggingEvent>();
		for (LoggingEvent e : logs) {
			if (e.getLoggerName().startsWith(name)) {
				l.add(e);
			}
		}
		return l;
	}

	public void addLog(LoggingEvent event) {
		logs.add(event);
	}

	public List<LoggingEvent> getLogs() {
		return logs;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public void setThreadID(Integer threadID) {
		this.threadID = threadID;
	}

	public Integer getThreadID() {
		return threadID;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getUrl() {
		return url;
	}

	public void setPageName(String pageName) {
		this.pageName = pageName;
	}

	public String getPageName() {
		return pageName;
	}

	public Class getPageClass() {
		return pageClass;
	}

	public void setPageClass(Class pageClass) {
		this.pageClass = pageClass;
	}

	public long getStartTime() {
		return startTime;
	}

	public long getEndTime() {
		return endTime;
	}

	public void setEndTime(long endTime) {
		this.endTime = endTime;
	}

}
